using System.ComponentModel;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
    public class NotifyBaseTest
    {

		public class Mock : NotifyBase
		{
			#region Fields

			public const string PropertyMember = "Property";
			private string property;

			#endregion


			#region Properties


			public string Property
			{
				get
				{
					return property;
				}
				set
				{
					if (property != value)
					{
						property = value;
						NotifyPropertyChanged(PropertyMember);
					}
				}
			}
#if (!WindowsCE)
			public string PropertyUsingExpression
			{
				get
				{
					return property;
				}
				set
				{
					if (property != value)
					{
						property = value;
						NotifyPropertyChanged(()=>PropertyUsingExpression);
					}
				}
			}
#endif
			#endregion
		}

		[TestFixture]
		public class PropertyChanged
		{

			private bool eventFired;

			[Test]
			public void Simple()
			{
			    eventFired = false;
				var mock = new Mock();

				mock.PropertyChanged += mock_PropertyChanged;

				mock.Property = "Foo";

				Assert.IsTrue(eventFired);
			}
#if (!WindowsCE)
			[Test]
			public void Expression()
			{
			    eventFired = false;
				var mock = new Mock();

				mock.PropertyChanged += mock_PropertyChanged;

				mock.PropertyUsingExpression = "Foo";

				Assert.IsTrue(eventFired);
			}
#endif

			void mock_PropertyChanged(object sender, PropertyChangedEventArgs e)
			{
					eventFired = true;
			}

		}

	}
}